﻿jQuery(function () {
    jQuery('ul.sf-menu').supersubs({ extraWidth: 1, minWidth: 12 }).superfish();

    $(".slide").cycle({ cleartype: false });

    $("#lnkMusic").live("click", function () {
        var bgAudio = document.getElementsByClassName("bg-audio");

        bgAudio[0].muted = !bgAudio[0].muted;

        setCookie('audio_muted', bgAudio[0].muted, 360);
    });

    $(".fancy-box").fancybox();

});

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function resizeMainContent() {

    var contentHeight = $("#mainContent").height();
    var headerHeight = $("header").height();
    var footerHeight = $("footer").height();
    var logoHeight = $(".logo").height();
    var screenHeight = window.screen.availHeight;

    if (headerHeight + contentHeight + footerHeight + logoHeight < screenHeight) {
        $("#mainContent").height(screenHeight - headerHeight - footerHeight - logoHeight);
    }
}

function checkAudioStatus() {
    var audio_muted = getCookie("audio_muted");
    if (audio_muted != null && audio_muted != "") {
        var bgAudio = document.getElementsByClassName("bg-audio");
        if (audio_muted == "true") {
            bgAudio[0].muted = true;
        }
    }
}

$(document).ready(function () {
    resizeMainContent();
    checkAudioStatus();
});